package cl.sujey.utils;

public class MathUtils {

	public static boolean isPrime(int number) {

		for (int i = 2; i < number; i++) {
			if (number % i == 0) {
				return false;
			}
		}

		return true;
	}

	public static boolean isPerfect(int number) {

		/* se obtienen los divisores */
		int[] divisores = MathUtils.getDivisores(number);
		if (ArrayUtils.sum(divisores) == number)
			return true;
		else
			return false;
	}

	public static int[] getDivisores(int number) {

		/* Contemos los divismores? */
		int n = 1;
		for (int i = 2; i < number; i++) {
			if (number % i == 0) {
				n++;
			}
		}

		int[] losDivisores = new int[n];
		losDivisores[0] = 1;

		int pos = 1;
		for (int i = 2; i < number; i++) {
			if (number % i == 0) {
				losDivisores[pos] = i;
				pos++;
			}
		}

		return losDivisores;
	}

	public static void main(String[] args) {

		int contador = 0;
		int i = 0;
		while (contador < 10) {

			if (isPerfect(i)) {
				System.out.println(i);
				contador++;
			}

			i++;
		}
	}

	/**
	 * This method is responsible for determining whether a given number is pair
	 * or no.
	 * 
	 * @param number
	 *            The number to be tested to be pair.
	 * @return <code>true</code> if the number is pair and <code>false</code>
	 *         otherwise.
	 */
	public static boolean isPair(int number) {
		return (number % 2 == 0);
	}
}

/*
 * Un numero es perfecto si la suma de sus divisores es el mismo numero. 3 : 1no
 * 4 : 1 2 5 : 1 no 6 : 1 2 3 ES PERFECTO! 7 : 1 8 : 1 2 4 -> 7 9 : 1 3 _4 10 :
 * 1 2 5 _ 8 11 12 : 1 2 3 4 6 --> 16
 */